using System;
using System.Globalization;
using System.Windows.Data;

namespace Lib.Helper
{
    public class DateConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null || value.ToString().Contains("0001"))
                return string.Empty;
            if (value.GetType() != typeof(DateTime)) return value;
            culture = new CultureInfo("ID-id");
            return ((DateTime)value).ToShortDateString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (string.IsNullOrEmpty(value.ToString())) return System.Convert.ToDateTime("01-01-001");
            culture = new CultureInfo("ID-id");
            return System.Convert.ToDateTime(value);
        }
    }
}
